/**
Nectarine Utility Project is a software interface for the web system 'demovibes'
Copyright (C) 2010  Alexandre LAURENT

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

website: http://code.google.com/p/nectarine-utility-project/
e-mail: lw.demoscene@gmail.com
**/

#include "groupinfodialog.h"

#include <QDialog>
#include <QWidget>
#include <QVBoxLayout>
#include <QPushButton>
#include <QLabel>
#include <QFrame>
#include <QListWidget>

#include <QDebug>

#include "globals.h"

GroupInfoDialog::GroupInfoDialog(const Group& g, QWidget *parent) :
    QDialog(parent)
{
    this->setWindowTitle(tr("NUP : Group %1 viewer").arg(g.id));
    this->setWindowIcon(QIcon(ICONSDIR + QString("group.png")));

    pMainGrid = new QVBoxLayout(this);

    pNameLabel = new QLabel(QString("<b>") + g.name + QString("</b>"),this);
    if ( !g.website.isEmpty())
    {
        pWebsiteLabel = new QLabel(QString("<a href=\"") + g.website.toString() + QString("\">") + g.website.toString() + QString("</a>"),this);
        pWebsiteLabel->setOpenExternalLinks(true);
    }
    else
    {
        pWebsiteLabel = NULL;
    }

    pHLine1 = new QFrame(this);
    pHLine1->setFrameStyle(QFrame::HLine);
    pHLine1->setLineWidth(1);

    if ( g.listArtist.size() != 0 ) // This case should not exist ...
    {
        pArtistLabel = new QLabel(QString(tr("Artists:")),this);
        pArtistsViewer = new QListWidget(this);

        for ( QList<Artist>::const_iterator itArtist = g.listArtist.begin() ; itArtist != g.listArtist.end() ; ++itArtist )
        {
            pArtistsViewer->addItem(itArtist->nickname);
        }
    }
    else
    {
        pArtistLabel = NULL;
        pArtistsViewer = NULL;
    }

    if ( g.listSongs.size() != 0 )
    {
        pSongLabel = new QLabel(QString(tr("Songs:")),this);
        pSongsViewer = new QListWidget(this);

        for ( QList<Song>::const_iterator itSong = g.listSongs.begin() ; itSong != g.listSongs.end() ; ++itSong)
        {
            pSongsViewer->addItem(itSong->title);
        }
    }
    else
    {
        pSongLabel = NULL;
        pSongsViewer = NULL;
    }

    if ( g.pouetId != 0 )
    {
        pHLine2 = new QFrame(this);
        pHLine2->setFrameStyle(QFrame::HLine);
        pHLine2->setLineWidth(1);

        pAdditionnalInfoLabel = new QLabel(QString("<b>") + QString(tr("Additionnal info:")) + QString("</b>"),this);

        pPouetLink = new QLabel(QString("<a href=\"http://www.pouet.net/group.php?which=%1\">Pouet Link</a>").arg(g.pouetId),this);
        pPouetLink->setOpenExternalLinks(true);
    }
    else
    {
        pHLine2 = NULL;
        pAdditionnalInfoLabel = NULL;
        pPouetLink = NULL;
    }

    pValidateButton = new QPushButton(tr("Ok"),this);

    pMainGrid->addWidget(pNameLabel,0,Qt::AlignHCenter);
    if ( pWebsiteLabel )
    {
        pMainGrid->addWidget(pWebsiteLabel,0,Qt::AlignHCenter);
    }
    pMainGrid->addWidget(pHLine1);
    if ( g.listArtist.size() != 0 )
    {
        pMainGrid->addWidget(pArtistLabel,0,Qt::AlignHCenter);
        pMainGrid->addWidget(pArtistsViewer,0,Qt::AlignHCenter);
    }

    if ( g.listSongs.size() != 0 )
    {
        pMainGrid->addWidget(pSongLabel,0,Qt::AlignHCenter);
        pMainGrid->addWidget(pSongsViewer,0,Qt::AlignHCenter);
    }

    if ( g.pouetId != 0 )
    {
        pMainGrid->addWidget(pHLine2);
        pMainGrid->addWidget(pAdditionnalInfoLabel,0,Qt::AlignHCenter);
        pMainGrid->addWidget(pPouetLink,0,Qt::AlignHCenter);
    }

    pMainGrid->addWidget(pValidateButton);

    connect(pValidateButton, SIGNAL(clicked()), this, SLOT(accept()));

    qDebug() << "GroupInfoDialog created";
}

GroupInfoDialog :: ~GroupInfoDialog(void)
{
    qDebug() << "GroupInfoDialog deleted";
}

void GroupInfoDialog :: accept(void)
{
    qDebug() << "GroupInfoDialog :: accept";

    this->done(QDialog::Accepted);
    emit deleteGIDSignal(this);
}

void GroupInfoDialog :: reject(void)
{
    qDebug() << "GroupInfoDialog :: reject";

    this->done(QDialog::Rejected);
    emit deleteGIDSignal(this);
}
